set.seed(123)
# Set working directory
setwd("/Users/ericguntermann/Documents/Papers/Representation of Party Preferences/Replication")


# This section produces the models for complete separation

criteria <- read.dta("criteria.dta")
criteria <- criteria[-which(criteria$countryyear %in% c("Thailand 2001", "Thailand 2011", "Japan 1996", "Japan 2013")),]
library(arm)
mod1 <- bayesglm(mostliked ~ proportional + freedomhouse + gdppercap, data=criteria, family=binomial(link="logit"))
mod2 <- bayesglm(mostliked ~ proportional + freedomhouse + gdppercap, data=criteria, family=binomial(link="probit"))


apsrtable(mod1,mod2)


# This produces the frequentist results:
library(apsrtable)
library(foreign)
criteria <- read.dta("criteria.dta")
criteria2 <- criteria[-which(criteria$countryyear %in% c("Thailand 2001", "Thailand 2011","Japan 1996", "Japan 2013")),]
#Criterion 1
mod1 <- lm(propfic ~ proportional + gdppercap + freedomhouse, data=criteria2)
mod2 <- lm(propfic ~ log(gallagher) + gdppercap + freedomhouse, data=criteria)
mod3 <- lm(propfic ~ log(mdm) + gdppercap + freedomhouse, data=criteria)
mod4 <- lm(propfic ~ proportional + ngov + gdppercap + freedomhouse, data=criteria2)
apsrtable(mod1,mod2,mod3)
apsrtable(mod4)

#Criterion 2
mod1 <- glm(mostliked ~ log(gallagher) + gdppercap + freedomhouse, data=criteria, family="binomial"(link="probit"))
mod2 <- glm(mostliked ~ log(mdm) + gdppercap + freedomhouse, data=criteria, family="binomial"(link="probit"))
apsrtable(mod1,mod2)
mod3 <- glm(mostliked ~ log(gallagher) + ngov + gdppercap + freedomhouse, data=criteria, family="binomial"(link="probit"))
mod4 <- glm(mostliked ~ log(mdm) + ngov + gdppercap + freedomhouse, data=criteria, family="binomial"(link="probit"))
apsrtable(mod3,mod4)

#Criterion 3
mod1 <- lm(lddiff ~ proportional + gdppercap + freedomhouse, data=criteria2)
mod2 <- lm(lddiff ~ log(gallagher) + gdppercap + freedomhouse, data=criteria)
mod3 <- lm(lddiff ~ log(mdm) + gdppercap + freedomhouse, data=criteria)
apsrtable(mod1,mod2,mod3)
mod4 <- lm(lddiff ~ log(mdm) + ngov + gdppercap + freedomhouse, data=criteria)
apsrtable(mod4)


# See ties no ties.R for results with no ties and parliamentary.R for analyses only for parliamentary systems


